package com.invest.infra.excel.upload.vo;

import com.google.common.collect.Lists;
import com.invest.config.AppProperties;
import com.invest.infra.constants.AppConstants;
import com.invest.utils.date.DateParseHelper;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

public class SheetErrorResult implements Serializable {

	// sheet名字
	private String sheetName;

	// 成功的行数
	private int successCount = 0;

	// 失败的行数
	private int failCount = 0;

	// 模板错误描述信息
	private String errorMessage;

	// 错误文件地址
	private String errorFileUri;

	// 详细数据信息
	private List<RowErrorResult> errorResults = Lists.newArrayList();

	public SheetErrorResult(String sheetName){
		this.sheetName = sheetName;
	}

	public void addSuccess(){
		successCount ++;
	}
	public void addFail(){
		failCount ++;
	}


	public int getSuccessCount() {
		return successCount;
	}

	public void setSuccessCount(int successCount) {
		this.successCount = successCount;
	}

	public int getFailCount() {
		return failCount;
	}

	public void setFailCount(int failCount) {
		this.failCount = failCount;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getErrorFileUri() {
		return errorFileUri;
	}

	public void setErrorFileUri(String errorFileUri) {
		this.errorFileUri = errorFileUri;
	}

	public List<RowErrorResult> getErrorResults() {
		return errorResults;
	}

	public void setErrorResults(List<RowErrorResult> errorResults) {
		this.errorResults = errorResults;
	}

	public String getSheetName() {
		return sheetName;
	}

	public void setSheetName(String sheetName) {
		this.sheetName = sheetName;
	}

	public String buildErrorFileUri(AppProperties appProperties,ExcelVO vo){


		StringBuilder filePathBuilder = new StringBuilder();
		filePathBuilder.append(DateParseHelper.format(new Date(),DateParseHelper.DATE_STRING_LONG));
		filePathBuilder.append(AppConstants.SEPARATOR_PATH);
		filePathBuilder.append(vo.getOperator()).append("_");
		//大并发的时候需要考虑下
		filePathBuilder.append(new Date().getTime()).append("_error_").append(vo.getFileName());

		String filePath = filePathBuilder.toString();
		setErrorFileUri(appProperties.getTemporaryUriPath()+AppConstants.SEPARATOR_PATH+filePath);
		return appProperties.getTemporaryDiskPath()+ AppConstants.SEPARATOR_PATH+filePath;
	}
}
